package edu.famework.demoZ1;

import com.foreknow.demo2.Admin;

import java.io.*;
import java.nio.Buffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Student {
    private int id;
    private String name;
    private String tell;
    private String age;
    private String address;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTell() {
        return tell;
    }

    public void setTell(String tell) {
        this.tell = tell;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * 输出集合的信息
     */
    public void outMess(List<Student> list){

        FileWriter fileWriter = null;
        try {
            fileWriter = new FileWriter("one.txt");
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
            for (int i = 0; i < list.size(); i++) {
                Student stu = list.get(i);
                int id = stu.getId();
                String name = stu.getName();
                String tell = stu.getTell();
                String age = stu.getAge();
                String adress = stu.getAddress();

                bufferedWriter.write(id+"  "+name+"  "+tell+"  "+age+"  "+adress);
            }
            bufferedWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        //创建集合进行输入信息
        List<Student> list = new ArrayList<>();

        Scanner input = new Scanner(System.in);
        for (int i = 0; i < 2; i++) {
            Student student = new Student();
            System.out.println("请输入学生编号:");
            int id = input.nextInt();
            student.setId(id);

            System.out.println("请输入学生姓名:");
            String name = input.next();
            student.setName(name);

            System.out.println("请输入学生电话:");
            String tell = input.next();
            student.setTell(tell);

            System.out.println("请输入学生年龄:");
            String age = input.next();
            student.setAge(age);

            System.out.println("请输入学生住址:");
            String address = input.next();
            student.setAddress(address);

            list.add(student);
        }
        Student stu1 = new Student();
        stu1.outMess(list);
        //对one文件中的信息读
        try {
            FileReader fileReader = new FileReader("one.txt");
            BufferedReader br = new BufferedReader(fileReader);
            FileWriter fileWriter = new FileWriter("student.txt");
            BufferedWriter bw = new BufferedWriter(fileWriter);
            //读取一个文本行
            String str = br.readLine();
            while (br.readLine() != null) {
                bw.write(str);
                //换行
                bw.newLine();
                str = br.readLine();
            }
            br.close();
            bw.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }




    }

}
